﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data.SqlClient;

namespace Cocbook_DAL
{
    public class Connection
    {
        
        public string GetConnectString()
        {
            return System.IO.File.ReadAllText("connectstring.dat"); 
        }

        public void SetConnectString(string s)
        {
            System.IO.File.WriteAllText("connectstring.dat",s); 
        }

        public bool CheckConnection()
        {
            try
            {
                string s = GetConnectString();
                SqlConnection sc = new SqlConnection(s);
                sc.Open();
                sc.Close();
                return true;
            }
            catch (Exception e)
            {
                Logger.Instance.Log("Program.Main.Test.CheckConnection", e.ToString());
                return false;
            }
        }
    }
}
